<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table border="1" cellspacing="0" cellpadding="10" id="tableId">
			<tr>
				<th></th>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>家庭住址</th>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="nan" /></td>
				<td>张三</td>
				<td >男</td>
				<td>20</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="nan" /></td>
				<td>李四</td>
				<td >男</td>
				<td>21</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="nv" /></td>
				<td>小芳</td>
				<td >女</td>
				<td>18</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="nan" /></td>
				<td>小刚</td>
				<td >男</td>
				<td>20</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="nv" /></td>
				<td>小玲</td>
				<td id="nv">女</td>
				<td>20</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="nv" /></td>
				<td>小何</td>
				<td >女</td>
				<td>21</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="nan" /></td>
				<td>小二</td>
				<td >男</td>
				<td>22</td>
				<td>福建省新罗区</td>
			</tr>
			
		</table><br>
			<td>
				<input type="checkbox" name="" id="checkAllID" value=""onclick="checkAll()" />全选
				<input type="checkbox" name="" id="checknanid" value="" onclick="checknan()"/>全选男
				<input type="checkbox" name="" id="checknvid" value="" onclick="checknv()"/>全选女
			</td>
			
	</body>
	<script type="text/javascript">
		function checkAll(){
			var tableobj=document.getElementById('tableId')
			var inputobj=tableobj.getElementsByTagName('input')
			var all=document.getElementById('checkAllID')
			for (var i = 0; i < inputobj.length; i++) {
				inputobj[i].checked=all.checked
			}
			console.log(inputobj)
		}
		function checknan(){
			var tableobj=document.getElementById('tableId')
			var inputobj=tableobj.getElementsByTagName('input')
			var all=document.getElementById('checknanid')
			for (var i = 0; i < inputobj.length; i++) {
				if (inputobj[i].value=='nan') {
					inputobj[i].checked=all.checked
				}
			}
		}
		function checknv(){
			var tableobj=document.getElementById('tableId')
			var inputobj=tableobj.getElementsByTagName('input')
			var all=document.getElementById('checknvid')
			for (var i = 0; i < inputobj.length; i++) {
				if (inputobj[i].value=='nv') {
					inputobj[i].checked=all.checked
				}
			}
		}
	</script>
	
</html>
